//
//  MoneyDistanceView.swift
//  JiaoZiTaxi
//
//  Created by shanzachattha8@gmail.comArmy1122@ on 2025/6/7.
//

import SwiftUI


struct MoneyDistanceView: View
{
     var model : PathCoordinate
    
    var body: some View {
           HStack(spacing: 16) {
               InfoCardView(
                   icon: "距离",
                   title: "预估里程".localized(),
                   value: formatDistance(model.distance),
                   color: .blue
               )
               Divider().frame(height:30)
               InfoCardView2(
                   icon: "费用",
                   title: "预估花费",
                   value: formatPrice(model.price),
                   color: .green
               )
           }
           .padding()
           .background(Color.white)
           .cornerRadius(16)
           .shadow(radius: 4)
       }
    
    private func formatDistance(_ meters: Double) -> String {
//           if meters < 1000 {
//               return "\(Int(meters)) m"
//           } else {
               return String(format: "%.1f km", meters / 1000)
//           }
       }
       
       private func formatPrice(_ price: Double) -> String {
           return String(format: "%.2f kip", price)
       }
    }

struct InfoCardView: View {
    var icon: String
    var title: String
    var value: String
    var color: Color
    
    var body: some View {
        HStack(spacing: 8) {
            Image( icon)
                .foregroundColor(color)
                .font(.system(size: 24))
            
            VStack(alignment: .leading, spacing: 4) {
                Text("预估里程")
                    .font(.caption)
                    .foregroundColor(.gray)
                
                Text(value)
                    .font(.headline)
                    .foregroundColor(.primary)
            }
        }
        .frame(maxWidth: .infinity, alignment: .leading)
//        .padding()
    }
}

struct InfoCardView2: View {
    var icon: String
    var title: String
    var value: String
    var color: Color
    
    var body: some View {
        HStack(spacing: 8) {
            Image( icon)
                .foregroundColor(color)
                .font(.system(size: 24))
            
            VStack(alignment: .leading, spacing: 4) {
                Text("预估花费")
                    .font(.caption)
                    .foregroundColor(.gray)
                
                Text(value)
                    .font(.headline)
                    .foregroundColor(.primary)
            }
        }
        .frame(maxWidth: .infinity, alignment: .leading)
//        .padding()
    }
}
